// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const TcbRouter = require('tcb-router')

const db = cloud.database()

const rp = require('request-promise')


const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const app = new TcbRouter({
    event
  })

  app.router('post', async(ctx, next) => {
    // console.log('info', event.info)
    var options = {
        method: 'POST',
        uri: event.uri,
        body: {
            ...event.info
        },
        json: true // Automatically stringifies the body to JSON
    };
    ctx.body = await rp(options).then((res) => {
      // console.log("订单统计返回结果", res)
      return res
    }).catch(function (err) {
        // POST failed...
        console.log('POST failed...', err)
    });
  })



  return app.serve()
  
}